package com.Questions.doublePointer;

import java.util.*;

/**
 * 数据流中的移动平均值
 */
public class leetcode346 {
    class MovingAverage {
        double winSize;
        ArrayList<Double> nums=new ArrayList<>();
        public MovingAverage(int size) {
            winSize=size;
        }

        public double next(int val) {
            nums.add((double)val);
            double sum=0;
            int i=1;
            for(;i<=winSize&&nums.size()-i>=0;++i){
                sum+=nums.get(nums.size()-i);
            }
            double num=Math.min(winSize,i-1);
            return sum/num;
        }
    }
}
